/*
 * $Id: time.h,v 1.15.6.4 Broadcom SDK $
 * 
 * $Copyright: Copyright 2011 Broadcom Corporation.
 * This program is the proprietary software of Broadcom Corporation
 * and/or its licensors, and may only be used, duplicated, modified
 * or distributed pursuant to the terms and conditions of a separate,
 * written license agreement executed between you and Broadcom
 * (an "Authorized License").  Except as set forth in an Authorized
 * License, Broadcom grants no license (express or implied), right
 * to use, or waiver of any kind with respect to the Software, and
 * Broadcom expressly reserves all rights in and to the Software
 * and all intellectual property rights therein.  IF YOU HAVE
 * NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS SOFTWARE
 * IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE
 * ALL USE OF THE SOFTWARE.  
 *  
 * Except as expressly set forth in the Authorized License,
 *  
 * 1.     This program, including its structure, sequence and organization,
 * constitutes the valuable trade secrets of Broadcom, and you shall use
 * all reasonable efforts to protect the confidentiality thereof,
 * and to use this information only in connection with your use of
 * Broadcom integrated circuit products.
 *  
 * 2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS
 * PROVIDED "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
 * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY,
 * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE.  BROADCOM SPECIFICALLY
 * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
 * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
 * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
 * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING
 * OUT OF USE OR PERFORMANCE OF THE SOFTWARE.
 * 
 * 3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL
 * BROADCOM OR ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL,
 * INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER
 * ARISING OUT OF OR IN ANY WAY RELATING TO YOUR USE OF OR INABILITY
 * TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF
 * THE AMOUNT ACTUALLY PAID FOR THE SOFTWARE ITSELF OR USD 1.00,
 * WHICHEVER IS GREATER. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING
 * ANY FAILURE OF ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.$
 * 
 * DO NOT EDIT THIS FILE!
 * This file is auto-generated.
 * Edits to this file will be lost when it is regenerated.
 */

#ifndef __BCM_TIME_H__
#define __BCM_TIME_H__

#include <bcm/types.h>

/* Time Interface Identifier. */
typedef int bcm_time_if_t;

#define BCM_TIME_ENABLE         0x00000001 /* Enable Time Synchronization
                                              Interface */
#define BCM_TIME_WITH_ID        0x00000002 /* Create/Update interface with valid
                                              identifier in the structure */
#define BCM_TIME_REPLACE        0x00000004 /* Replace current interface settings
                                              according to flags provided */
#define BCM_TIME_INPUT          0x00000008 /* Current interface will recieve a
                                              time sync messages (Act as slave) */
#define BCM_TIME_DRIFT          0x00000020 /* To set/get the drift parameter for
                                              Interface */
#define BCM_TIME_OFFSET         0x00000040 /* To set/get the offset parameter
                                              for Interface */
#define BCM_TIME_ACCURACY       0x00000080 /* To set/get the accuracy parameter
                                              for Interface */
#define BCM_TIME_HEARTBEAT      0x00000100 /* To set the heartbeat frequency for
                                              Interface */
#define BCM_TIME_LOCKED         0x00000200 /* To indicate that interface is
                                              locked on a grand master's
                                              clock */
#define BCM_TIME_REF_CLOCK      0x00000400 /* Enable Reference clock */

/* Base time structure. */
typedef struct bcm_time_interface_s {
    uint32 flags;               /* Flags BCM_TIME_* */
    bcm_time_if_t id;           /* Time Interface Identifier */
    bcm_time_spec_t drift;      /* Drift amount per 1 Sec */
    bcm_time_spec_t offset;     /* Offset */
    bcm_time_spec_t accuracy;   /* Accuracy */
    int heartbeat_hz;           /* HeartBeat Rate */
    int clk_resolution;         /* Reference clock resolution in nsecs */
} bcm_time_interface_t;

#define BCM_TIME_CAPTURE_LOCKED             0x00000001 /* Captured Time is
                                                          synchronized with
                                                          Grand Master */
#define BCM_TIME_CAPTURE_GPIO_0             0x00000002 /* Capture Time at rising
                                                          edge of GPIO 0 */
#define BCM_TIME_CAPTURE_GPIO_1             0x00000004 /* Capture Time at rising
                                                          edge of GPIO 1 */
#define BCM_TIME_CAPTURE_GPIO_2             0x00000008 /* Capture Time at rising
                                                          edge of GPIO 2 */
#define BCM_TIME_CAPTURE_GPIO_3             0x00000010 /* Capture Time at rising
                                                          edge of GPIO 3 */
#define BCM_TIME_CAPTURE_GPIO_4             0x00000020 /* Capture Time at rising
                                                          edge of GPIO 4 */
#define BCM_TIME_CAPTURE_GPIO_5             0x00000040 /* Capture Time at rising
                                                          edge of GPIO 5 */
#define BCM_TIME_CAPTURE_L1_CLOCK_PRIMARY   0x00000080 /* Capture Time at rising
                                                          edge of primary L1 */
#define BCM_TIME_CAPTURE_L1_CLOCK_SECONDARY 0x00000100 /* Capture Time at rising
                                                          edge of primary L2 */
#define BCM_TIME_CAPTURE_LCPLL              0x00000200 /* Capture Time at rising
                                                          edge of LCPLL */
#define BCM_TIME_CAPTURE_IP_DM_0            0x00000400 /* Capture Time at rising
                                                          edge of DM0 */
#define BCM_TIME_CAPTURE_IP_DM_1            0x00000800 /* Capture Time at rising
                                                          edge of DM1 */
#define BCM_TIME_CAPTURE_IMMEDIATE          0x00001000 /* Capture Immediate */
#define BCM_TIME_CAPTURE_ALL                0x00002000 /* Capture Immediate */

/* Base time capture structure. */
typedef struct bcm_time_capture_s {
    uint32 flags;                       /*  Flags BCM_TIME_CAPTURE_* */
    bcm_time_spec_t free;               /* Free running clock */
    bcm_time_spec_t syntonous;          /* Syntonous clock */
    bcm_time_spec_t synchronous;        /* Synchronous clock */
    bcm_time_spec_t received;           /* Received clock */
    bcm_time_spec_t received_accuracy;  /* Received clock accuracy */
} bcm_time_capture_t;

#ifndef BCM_HIDE_DISPATCHABLE

/*  Initialize time module */
extern int bcm_time_init(
    int unit);

/*  Uninitialize time module */
extern int bcm_time_deinit(
    int unit);

#endif /* BCM_HIDE_DISPATCHABLE */

/*  Initialize bcm_time_spec_t structure */
extern void bcm_time_spec_t_init(
    bcm_time_spec_t *spec);

/*  Initialize bcm_time_interface_t structure */
extern void bcm_time_interface_t_init(
    bcm_time_interface_t *intf);

/*  Initialize bcm_time_capture_t structure */
extern void bcm_time_capture_t_init(
    bcm_time_capture_t *capture);

#ifndef BCM_HIDE_DISPATCHABLE

/* Add a time sync interfaces on a unit */
extern int bcm_time_interface_add(
    int unit, 
    bcm_time_interface_t *intf);

/* Get a time sync interfaces on a unit */
extern int bcm_time_interface_get(
    int unit, 
    bcm_time_interface_t *intf);

/* Delete a time sync interfaces on a unit */
extern int bcm_time_interface_delete(
    int unit, 
    bcm_time_if_t intf_id);

/* Delete all time sync interfaces on a unit */
extern int bcm_time_interface_delete_all(
    int unit);

#endif /* BCM_HIDE_DISPATCHABLE */

/* bcm_time_interface_traverse_cb */
typedef int (*bcm_time_interface_traverse_cb)(
    int unit, 
    bcm_time_interface_t *intf, 
    void *user_data);

#ifndef BCM_HIDE_DISPATCHABLE

/* bcm_time_interface_traverse */
extern int bcm_time_interface_traverse(
    int unit, 
    bcm_time_interface_traverse_cb cb, 
    void *user_data);

/* Gets HW clocks capture */
extern int bcm_time_capture_get(
    int unit, 
    bcm_time_if_t intf_id, 
    bcm_time_capture_t *time);

#endif /* BCM_HIDE_DISPATCHABLE */

/* bcm_time_heartbeat_cb */
typedef int (*bcm_time_heartbeat_cb)(
    int unit, 
    bcm_time_if_t id, 
    bcm_time_capture_t *time, 
    void *user_data);

#ifndef BCM_HIDE_DISPATCHABLE

/* Register callback function to be called on heartbeat */
extern int bcm_time_heartbeat_register(
    int unit, 
    bcm_time_if_t id, 
    bcm_time_heartbeat_cb f, 
    void *user_data);

/* Unregister callback function */
extern int bcm_time_heartbeat_unregister(
    int unit, 
    bcm_time_if_t id);

/* bcm_time_heartbeat_enable_set */
extern int bcm_time_heartbeat_enable_set(
    int unit, 
    bcm_time_if_t id, 
    int enable);

/* bcm_time_heartbeat_enable_get */
extern int bcm_time_heartbeat_enable_get(
    int unit, 
    bcm_time_if_t id, 
    int *enable);

/* bcm_time_trigger_enable_set */
extern int bcm_time_trigger_enable_set(
    int unit, 
    bcm_time_if_t id, 
    uint32 mode_flags);

/* bcm_time_trigger_enable_get */
extern int bcm_time_trigger_enable_get(
    int unit, 
    bcm_time_if_t id, 
    uint32 *mode_flags);

#endif /* BCM_HIDE_DISPATCHABLE */

#endif /* __BCM_TIME_H__ */
